package com.rogan.rpc.client.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

import com.rogan.rpc.rpcserver.ServiceObject;
import com.rogan.rpc.server.ServiceInfo;

public class BioNetClient implements NetClient {
	private Socket socket;
	@Override
	public byte[] sendRequest(byte[] data, ServiceInfo sinfo) {
		String rs = "";
		try {
			 socket = new Socket("127.0.0.1", 8081);
				OutputStream output = socket.getOutputStream();
				output.write(data);
				 
				output.flush();
            System.out.println("read start");
            int result=0;
            BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
            while((result=rd.read())!=-1)
            {
                System.out.print((char)result);
                rs += (char)result;
            }
		      System.out.println("read complete");
			// ObjectInput objectInput = new ObjectInputStream(socket.getInputStream());
			//
			// ServiceObject serviceObject = (ServiceObject) objectInput.readObject();
			// objectInput.close();
			// String name = serviceObject.getName();
			// System.out.println(name);
			
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return rs.getBytes();
	}

	 
}

